package com.yxmadoc.umlproject.controller;

import com.alibaba.fastjson.JSONObject;
import com.yxmadoc.umlproject.config.enums.ReturnResult;
import com.yxmadoc.umlproject.model.Customer;
import com.yxmadoc.umlproject.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/customer")
    public JSONObject insert(@RequestBody Customer customer){
        JSONObject result = new JSONObject();
        result.put(ReturnResult.DATA.getCode(), customerService.save(customer));
        return result;
    }

    @GetMapping("/customer/{customerId}")
    public JSONObject detail(@PathVariable("customerId")String customerId){
        JSONObject data = new JSONObject();
        data.put(ReturnResult.DATA.getCode(), customerService.findOne(customerId));
        return data;
    }

    
}
